﻿#pragma once
#pragma execution_character_set("utf-8")
#include "DataHandler.h"
#include <QDate>
#include <QtWidgets/QWidget>
#include "ui_OneKeyboard.h"
#include "HDBase/DList.hpp"
#include "HDBase/DMap.hpp"
#include "hook.h"

class KeyButton;

enum TimeType
{
	Current,
	Day,
	Week,
	Month,
	Year
};

class OneKeyboard : public QWidget
{
    Q_OBJECT

public:
    OneKeyboard(QWidget *parent = Q_NULLPTR);
	void show();
	void doBeforeExit();

public slots:
	void slotKeyPressed(const KeyInfo& info);
	void slotMousePressed(const MouseInfo& info);
	void slotButtonClicked();
	void slotBtnBarChanged(QPushButton* btn, QVariant data);
	void on_tab_key_currentChanged(int index);
	void on_btn_prev_day_clicked();
	void on_btn_next_day_clicked();
	void on_btn_prev_week_clicked();
	void on_btn_next_week_clicked();
	void on_btn_prev_month_clicked();
	void on_btn_next_month_clicked();
	void on_btn_prev_year_clicked();
	void on_btn_next_year_clicked();
	void on_btn_reset_key_clicked();
	void on_btn_reset_mouse_clicked();
	void on_btn_hide_clicked();

private:
	void initMap();
	void refreshAll(const DataHandler::Data& data);
	void refreshKey(const DataHandler::Data& data);
	void refreshMouse(const DataHandler::Data& data);
	void refreshKeyText();
	void refreshLabelDate();
	void refreshStatWidget();  // 刷新统计图
	void newKeyClicked(KeyButton* btn);
	void slotDayNext();
	// 根据时间类型和时间index，刷新相关成员变量
	void refreshValues(const DataHandler::Data& data);
	// 根据时间类型和时间index，获取data
	DataHandler::Data generateData(TimeType type, const QDate& date);

	// 根据 TimeType 比较今天是否处于 QDate 中
	bool todayIsInTime(TimeType type, const QDate& date);

	void mousePressEvent(QMouseEvent* ev);
	void mouseMoveEvent(QMouseEvent* ev);
	void mouseReleaseEvent(QMouseEvent* ev);

    Ui::OneKeyboardClass ui;
	DMap<int, DList<QString>> mapKeyNames_;  // 每个按键key对应的btnName
	TimeType currentTimeType_;
	QDate currentDate_;  // 正在显示的日期，需要搭配 currentTimeType_ 使用
	DataHandler::Data dataCurrent_;  // 本次计数的按键数据
	int maxKeyCount_;
	KeyButton* maxKeyBtn_;
	int totalCount_;

	bool isPressed_;
	QPoint pressPos_;
};
